package com.bstek.weixin.wxInterface;

import java.io.IOException;
import java.util.Date;

import com.bstek.weixin.utils.BodyUtil;
import com.bstek.weixin.utils.ConstantlUtil;
import com.bstek.weixin.utils.DateUtil;
import com.bstek.weixin.utils.WeixinCommUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;

import com.alibaba.fastjson.JSONObject;

/**
 * 应用 打卡信息
 * @author snail
 * @date 2019年1月2日
 */
public class CheckInInterFace {
	
	public static final Logger log=LoggerFactory.getLogger(CheckInInterFace.class);
	/**
	*@Description  获取 打卡信息
	*@Author snail
	*@Date
	*@return
	**/
	public static JSONObject getCheckinData(String checkinBody) throws IOException {
		//获取打卡信息url
		if(StringUtils.hasText(checkinBody)) {
			String checkinURL= ConstantlUtil.getCheckinDataURL;
			String accessToken= WeixinCommUtil.getWeixinToken(ConstantlUtil.corpId, ConstantlUtil.checkSecret);
			checkinURL=checkinURL.replace("ACCESS_TOKEN", accessToken);
			JSONObject json=WeixinCommUtil.operatorWeixin(checkinURL, "POST", checkinBody);
			log.info("打卡信息"+json);
			return json;
		}else {
			log.info("查询打卡信息参数为空"+checkinBody);
			return null;
		}
		
	}

	/**
	*@Description  测试打卡信息
	*@Author snail
	*@Date 2019/1/7
	*@return void
	**/
	public static void main(String[] args) throws Exception {
		Date startDate= DateUtil.getDate("yyyyMMdd HH:mm:ss", "20181214 00:00:00");
		Date endDate=DateUtil.getDate("yyyyMMdd HH:mm:ss", "20181217 00:00:00");
		String userids[]={"BaiGuoYu"};
		String checkinBody= BodyUtil.checkinBody(3,startDate,endDate,userids);
		JSONObject json=getCheckinData(checkinBody);
		System.out.println("打卡信息："+json.toString());
	}
}
